

	var recModule = Ext.data.Record.create(['moduleCode', 'moduleTitleKey', 'moduleTitleKeyCn', 'moduleTitleKeyEn', 'moduleDescKey','clientType']);
	var recMenuGroup = Ext.data.Record.create(['menuGrpSeq', 'menuGrpTitleKey', 'menuGrpTitleKeyCn', 'menuGrpTitleKeyEn', 'menuGrpDescKey']);
	var recMenuItem = Ext.data.Record.create(['viewId', 'menuItemUrl', 'menuItemSeq', 'menuItemDescKey','showInConsole','showInMenu','isDialog','isNewFun']);
	var recViewButton = Ext.data.Record.create(['buttonUrl', 'btnName', 'btnTitleKey', 'btnMsgKey']);
	var root = new Ext.tree.TreeNode({id:'root',text: i18n.nav.MenuManagement});
		
	AuthFunctionService.loadAllModule(function(modules){
		// load module
	    Ext.each(modules, function(md){
			var mdNode = new Ext.tree.TreeNode({
	    		text : Gfa.CommonUtil.getTitle(md.moduleTitles),
	    		iconCls : 'module'
			});
	    	mdNode.authType = 'Module';
	    	mdNode.authData = md;
	    	root.appendChild(mdNode);
			
			// load menuGroup
			Ext.each(md.menuGroups, function(mg){
				var mgNode = new Ext.tree.TreeNode({
		    		text : Gfa.CommonUtil.getTitle(mg.menuGroupTitles),
		    		iconCls : 'menuGroup'
				});
		    	mgNode.authType = 'MenuGroup';
	    		mgNode.authData = mg;
	    		mdNode.appendChild(mgNode);
		    	
		    	// load menuItem
		    	Ext.each(mg.menuItems, function(mi){
		    		var miNode = new Ext.tree.TreeNode({
			    		text : Gfa.CommonUtil.getTitle(mi.menuItemTitles),
			    		iconCls : 'menuItem'
					});
			    	miNode.authType = 'MenuItem';
		    		miNode.authData = mi;
		    		mgNode.appendChild(miNode);
		    		
			    	// load viewButton
			    	Ext.each(mi.viewButtons, function(vb){
			    		var vbNode = new Ext.tree.TreeNode({
				    		text : Gfa.CommonUtil.matchLanguage(vb['btnTitleKey']),
				    		iconCls : 'viewButton'
						});
				    	vbNode.authType = 'ViewButton';
			    		vbNode.authData = vb;
			    		miNode.appendChild(vbNode);
			    	});
		    	});
			});
	    });
	});
	
	var authTree = new Ext.tree.TreePanel({
		region : 'west',
		title: i18n.nav.MenuManagement,
		border: true,
		width: 200,
		height : 500,
		margins : '5 5 5 5',
		animate: false,
		autoScroll : true,
		rootVisible: false,
		root: root
	});
	
	
	authTree.on('click', function(node, e){
		if (node.hasChildNodes()) node.expand();
		var clicknum;
		var editingData = {};
		switch(node.authType) {
			case 'Module': 
				clicknum = 1;	
				editingData = node.authData;
				break;
			case 'MenuGroup':
				clicknum = 2;
				node.authData.moduleId = node.authData.module.moduleId;
				editingData = node.authData;
				break;
			case 'MenuItem':
				clicknum = 3;
				node.authData.menuGroupId = node.authData.menuGroup.menuGroupId;
				node.authData.moduleId = node.authData.menuGroup.module.moduleId;
				editingData = node.authData;
				break;
			case 'ViewButton':
				clicknum = 4;
				node.authData.menuItemId = node.authData.menuItem.menuItemId;
				node.authData.menuGroupId = node.authData.menuItem.menuGroup.menuGroupId;
				node.authData.moduleId = node.authData.menuItem.menuGroup.module.moduleId;
				editingData = node.authData;
				break;
			defaults: return;
		}
		
		nodeClick(clicknum, editingData);
	});
	
	var pnlFnMgr = new Ext.Panel({
		layout: 'column',
		items: [authTree]
	});	
	
	function getParentNode(authType) {
		var node = authTree.selModel.selNode;
		switch(authType) {
			case 'Module':
				return root;
			case 'MenuGroup':
				if (node.authType == 'Module') {
					return node;
				} else if (node.authType == 'MenuGroup') {
					return node.parentNode;
				} else if (node.authType == 'MenuItem') {
					return node.parentNode.parentNode;
				} else if (node.authType == 'ViewButton') {
					return node.parentNode.parentNode.parentNode;
				}
			case 'MenuItem':
				if (node.authType == 'MenuGroup') {
					return node;
				} else if (node.authType == 'MenuItem') {
					return node.parentNode;
				} else if (node.authType == 'ViewButton') {
					return node.parentNode.parentNode;
				}
			case 'ViewButton':
				if (node.authType == 'MenuItem') {
					return node;
				} else if (node.authType == 'ViewButton') {
					return node.parentNode;
				}
		}
	}
